package com.longrise.android.byjk.plugins.login.verifyphnumber;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity;
import com.longrise.android.byjk.model.UserInfor;
import com.longrise.android.byjk.plugins.login.ChangePasswordActivity;
import com.longrise.android.byjk.widget.view.InputBoxView;


/**
 * Created by callxkj on 2017/2/13.
 * 验证手机号码
 */

public class VerifyPhnumberActivity extends BaseActivity<VerifyPhnumberPresenter> implements VerifyPhnumberContract.View {

    private InputBoxView mIbvPn;
    private Button mBtcfm;
    private TextView mTvzh;
    private RelativeLayout mRlback;
    private TextView mTvtitle;

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_verifyphnumber;
    }

    @Override
    public void initView() {
        mRlback = (RelativeLayout) findViewById(R.id.relapp_back);
        mTvtitle = (TextView) findViewById(R.id.app_title);
        mTvzh = (TextView) findViewById(R.id.vfphnum_zh);
        mIbvPn = (InputBoxView) findViewById(R.id.verifyphonenumber_phone_num);
        mBtcfm = (Button) findViewById(R.id.verifyphonenumber_confirm);
        initData();
        initEvent();
    }

    private void initData() {
        mTvtitle.setText("验证手机号");
        String usersfzh = UserInfor.getInstance().getUsersfzh();
        mTvzh.setText(usersfzh);
    }

    private void initEvent() {
        //返回按钮
        mRlback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //确定按钮
        mBtcfm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toConfirm();
            }
        });


    }

    /**
     * 点击确定按钮
     */
    public void toConfirm() {
        showLoadingDialog();
        mBtcfm.setClickable(false);
        mPresenter.toConfirm(mIbvPn.getText());
    }

    @Override
    public void onOnFail(String msg) {
        onComplete();
        showToast(msg);
    }

    @Override
    public void onSuccess() {
        startActivity(ChangePasswordActivity.class);
    }

    @Override
    public void onComplete() {
        dismissLoadingDialog();
        mBtcfm.setClickable(true);
    }

}
